﻿using MediatR;
using SuYuanSystem.Applications;
using SuYuanSystem.Domain;
using SuYuanSystem.Repositories;
using SuYuanSystem.WebApi.MedialRs.Commands.Farmss;

namespace SuYuanSystem.WebApi.MedialRs.CommandHandlers.Farmss
{
    public class FarmsQueryCommandsHandlers : IRequestHandler<FarmsQueryCommands, ApiResult<Farms>>
    {
        public FarmsQueryCommandsHandlers(IRepository<Farms> repository)
        {
            Repository = repository;
        }

        public IRepository<Farms> Repository { get; }

        public Task<ApiResult<Farms>> Handle(FarmsQueryCommands request, CancellationToken cancellationToken)
        {
            try
            {
                ApiResult<Farms> result = new ApiResult<Farms>();
                result.statusCode = StatusCode.Success;
                result.Message = "查询成功";
                var list = Repository.GetAll();
                var entity = list.Result.FirstOrDefault();
                result.Data = entity;
                return Task.FromResult(result);
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
